<template>
	<view>
		<dsl-navbar title="企业认证" isBack bgTopImg="#ffffff"></dsl-navbar>
		<view class="rowsb padding solid-bottom">
			<view>
				企业名称
			</view>
			<input type="text" value="" placeholder="暂未填写" class="text-right" v-model="name" />
		</view>
		<view class="rowsb padding solid-bottom">
			<view>
				统一社会信用代码
			</view>
			<input type="text" value="" placeholder="暂未填写" class="text-right" v-model="credit" />
			<!-- <view class="cuIcon-right"></view> -->
		</view>
		<!-- <view class="cu-form-group">
			<view class="grid col-4 grid-square flex-sub">
				<view class="bg-img" v-for="(item,index) in upImgList" :key="index" :data-url="upImgList[index]"
					@click.stop="previewImages(index,upImgList)">
					<image :src="upImgList[index]" mode="aspectFill"></image>
					<view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
						<text class='cuIcon-close'></text>
					</view>
				</view>
				<view @tap="ChooseImage" v-if="upImgList.length<9">
					<image src="/static/user/imgshangchuan.png" mode="" class="imgshangchuan"></image>
				</view>
			</view>
		</view> -->
		<!-- <view class="text-sm text-gray padding-left">
			对公账户认证，认证信息 
		</view> -->
		<view class="rowsb padding solid-bottom">
			<view>
				经营范围
			</view>
			<input type="text" value="" placeholder="暂未填写" class="text-right" v-model="range" />
		</view>
		<view class="rowsb padding solid-bottom">
			<view>
				您的职位
			</view>
			<input type="text" value="" placeholder="暂未填写" class="text-right" v-model="position" />
		</view>
		<view class="rowsb padding solid-bottom">
			<view>
				姓名
			</view>
			<input type="text" value="" placeholder="暂未填写" class="text-right" v-model="username" />
		</view>
		<view class="rowsb padding solid-bottom">
			<view>
				身份证号
			</view>
			<input type="text" value="" placeholder="暂未填写" class="text-right" v-model="identity_card" />
		</view>
		<view class="rowsb padding solid-bottom">
			<view>
				联系方式
			</view>
			<input type="text" value="" placeholder="暂未填写" class="text-right" v-model=" mobile" />
		</view>
		<view class="padding text-sm text-red"> * 认证需要支付300保障金</view>
		<view class="submit" @click=" orderPay()">
			立即认证
		</view>
	</view>
</template>

<script>
	import {
		companyzheng,
		orderPay,
		paySubmit
	} from '@/common/path.js'
	export default {
		data() {
			return {
				// #ifdef H5
				name: "慧族网络科技发展有限公司", //企业名称
				credit:'91370112MA3NE2DWX0',
				range:'软件营销',
				position:'法人',
				username:'名称',
				mobile:'13176011182',
				identity_card:'37158120010320445x',
				// #endif
				// #ifdef APP-PLUS
				name: "", //企业名称
				credit: "", //统一信用代码
				range: "", //营业范围
				position: "", //职位
				username: "", //名称
				mobile: "", //联系方式
				identity_card: "", //身份证号
				orderData: '', //支付订单号
				// #endif
			}
			
			
		},
		methods: {

			//支付保障金 单号获取
			orderPay() {
				let data = {
					type: 1
				}
				this.Http.POST(orderPay, data).then(res => {
					if (res.code == 1) {
						console.log('[支付保障金300]', res.data);
						this.orderData = res.data

						let v = this

						uni.showActionSheet({
							itemList: ['微信支付', '支付宝支付'],
							success: function(res) {
								if (res.tapIndex == 0) {
									v.paySubmit(1)
								} else {
									v.paySubmit(2)
								}
							},
							fail: function(res) {
								console.log(res.errMsg);
							}
						});

					} else {
						this.companyzheng()
						this.$tools.showToast(res.msg)
					}
				})
			},
			//支付保障金
			paySubmit(payment_pattern) {
				let data = {
					orderno: this.orderData,
					payment_pattern: payment_pattern
				}
				this.Http.POST(paySubmit, data).then(res => {
					if (res.code == 1) {
						console.log('[支付成功300]', res);
						if (payment_pattern == 1) { //微信
							this.wxpay(res.data.data)
						} else { //支付宝
							this.alipay(res.data.data)
						}
					}else{
						this.$tools.showToast(res.msg)
					}
				})
			},
			//微信支付
			wxpay(data) {
				let that = this
				uni.requestPayment({
					provider: 'wxpay',
					orderInfo: data,
					success: (res) => {
						that.companyzheng()
					},
					fail: (res) => {
						console.log(res, 'fail');
					}
				})
			},
			//支付宝支付
			alipay(data) {
				let that = this
			 uni.requestPayment({
					provider: 'alipay',
					orderInfo: data,
					success: (res) => {
						that.companyzheng()
					},
					fail: (res) => {
						console.log(res, 'fail');
					}
				})
			},

			//认证
			companyzheng() {
				let v = this
				if (!v.name) {
					v.$tools.showToast('企业名称空')
					return
				}
				if (!v.credit) {
					v.$tools.showToast('统一信用代码空')
					return
				}
				if (!v.range) {
					v.$tools.showToast('营业范围空')
					return
				}
				if (!v.position) {
					v.$tools.showToast('职位空')
					return
				}
				if (!v.username) {
					v.$tools.showToast('名称空')
					return
				}
				if (!v.mobile) {
					v.$tools.showToast('联系方式空')
					return
				}
				if (!v.identity_card) {
					v.$tools.showToast('身份证号空')
					return
				}
				let data = {
					name: v.name, //企业名称
					credit: v.credit, //统一信用代码
					range: v.range, //营业范围
					position: v.position, //职位
					username: v.username, //名称
					mobile: v.mobile, //联系方式
					identity_card: v.identity_card, //身份证号
				}
				this.Http.POST(companyzheng, data)
					.then((res) => {
						if (res.code == 1) {
							v.$tools.showToast('提交成功')
							console.log('认证', res);
							getApp().globalData.weburl = res.data
							uni.navigateTo({
								url: '/pages/plugins/webwiew?title=' + '企业认证'
							})
						} else {
							v.$tools.showToast(res.msg)
						}
					})
			},
			//图片上传
			ChooseImage() {
				uni.chooseImage({
					count: 9,
					sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
					success: (event) => {
						uni.showLoading({
							'title': '上传中...'
						})
						event.tempFilePaths.forEach(item => {
							uni.uploadFile({
								url: 'https://m.yipanxueyuan.com/addons/alioss/index/upload',
								filePath: item,
								name: 'file',
								formData: {
									token: uni.getStorageSync('token'),
								},
								success: (res) => {
									console.log('shangchuan', res);
									let analysisImg = JSON.parse(res.data)
									if (analysisImg.code == 1) {
										this.upImgList.push(analysisImg.data.url)
										let img = this.upImgList.join(',')
										this.images = img
										uni.hideLoading()
									}
								},
								fail() {
									console.log('[失败]');
								},
								complete() {
									uni.hideLoading()
								}

							})
						})

					}
				})
			},
			DelImg(e) {
				uni.showModal({
					title: '温馨提示',
					content: '确定要删除该图片吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.upImgList.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},
			previewImages(index, array) {
				preview(index, array)
			},
		}
	}
</script>

<style>
	.imgshangchuan {
		width: 138rpx;
		height: 138rpx;
		background: #EEEEEE;
		opacity: 1;
	}

	.submit {
		width: 654rpx;
		height: 98rpx;
		background: #00D88F;
		box-shadow: 0px 1rpx 10rpx rgba(0, 216, 143, 0.5);
		opacity: 1;
		border-radius: 60rpx;
		line-height: 98rpx;
		text-align: center;
		color: white;
		margin: 0 auto;
		margin-top: 100rpx;
	}

	view {}

	input {
		width: 300rpx;
	}
</style>
